package directory.model;

import controller.ParametroMgr;
import java.sql.ResultSet;
import model.BasicBean;

public class PersonRelationType extends BasicBean {

    public String name = "";
    public String nameback = "";
    public String idPersonTypeA = "";
    public String idPersonTypeB = "";

    public PersonRelationType() {
    }

    public PersonRelationType(ResultSet rs) {
        try {
            id = validateString(rs.getString("id"));
            name = validateString(rs.getString("name"));
            nameback = validateString(rs.getString("nameback"));
            idPersonTypeA = validateString(rs.getString("idPersonTypeA"));
            idPersonTypeB = validateString(rs.getString("idPersonTypeB"));
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    @Override
    public String getHtmlRow() {
        String sz = "";
        sz += "<td class='st4middle'>" + ParametroMgr.mgr.getItemFromSql("select id, name from PersonType where id="+idPersonTypeA ).nombre + "</td>";
        sz += "<td class='st4middle'>" + name + "</td>";
//        sz += "<td class='st4middle'>" + nameback + "</td>";
        sz += "<td class='st4middle'>" + ParametroMgr.mgr.getItemFromSql("select id, name from PersonType where id="+idPersonTypeB ).nombre + "</td>";
        return sz;
    }

    @Override
    public String getUpdateSql() {
        String sql = "";
        if (id.equals("")) {
            sql = "insert into PersonRelationType( name, nameback, idPersonTypeA, idPersonTypeB ) values( '" +
                    name + "', '" +
                    nameback + "', '" +
                    idPersonTypeA + "', '" +
                    idPersonTypeB + "' )";
        } else {
            sql = "update PersonRelationType set name = '" +
                    name + "', nameback= '" +
                    nameback + "', idPersonTypeA= '" +
                    idPersonTypeA + "', idPersonTypeB= '" +
                    idPersonTypeB + "' where id = '" + id + "'";
        }
        return sql;
    }

    @Override
    public String getIdentifier() {
        return "idPersonRelationType=" + id;
    }
}